$(function() {
	jQuery.validator.addMethod("isphone", function(value, element) {   
		return this.optional(element) || /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/.test(value);   
	}, "请正确填写您的手机号码");
	
	$("#add_agent_form").validate({
		errorPlacement:function(error,element) {  
			element.parent().find(".verror").html(error);
		},
		rules:{
			"agent.agentName":{
				required:true,
				rangelength: [4, 20],
				remote: {
					url: base + "admin/agent/checkAgentName.action", 
					type: "POST", 
					data: {"agent.id": ($("#agent_id").val()), "agent.agentName": ($("#agent.agentName").val())}
				}
			},
			"agent.telephone":{
				required:true,
				isphone:true,
				rangelength: [7, 20],
				remote: {
					url: base + "admin/agent/checkTelephone.action", 
					type: "POST", 
					data: {"agent.id": ($("#agent_id").val()), "agent.telephone": ($("#agent.telephone").val())}
				}
			},
			"agent.email":{
				email:true,
				remote: {
					url: base + "admin/agent/checkEmail.action", 
					type: "POST", 
					data: {"agent.id": ($("#agent_id").val()), "agent.email": ($("#agent.email").val())}
				}
			}
		},
		messages:{
			"agent.agentName": {
				required: "请输入负责任人名称", 
				rangelength:"长度不能少于{0}和大于{1}个字符",
				remote: "该名称已被使用"
			},
			"agent.telephone": {
				required: "请输入联系电话",
				isphone: " 电话号码格式不正确",
				rangelength: " 长度不能少于{0}和大于{1}个字符",
				remote: " 该电话号码已被使用"
			}, 
			"agent.email": {
				email: " 电子邮箱格式不正确",
				remote: " 该邮箱已被使用"
			}
		}
	});
});